package cn.com.header.web.service.basic;

import cn.com.header.core.util.Page;
import cn.com.header.web.mapper.basic.SubjectDAO;
import cn.com.header.web.model.basic.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 学科Service接口实现类
 * Created by lhd on 2017/7/11.
 */
@Service
public class SubjectServiceImpl implements SubjectService {

    @Autowired
    private SubjectDAO subjectDao;

    @Override
    public Page query(Page page) {
       page.setResult(subjectDao.query(page));
       return page;
    }

    @Override
    @Transactional
    public void saveSubject(Subject subject) {
        if(subject.getId()==null){
            subject.setCjsj(new Date());
            subjectDao.insert(subject);
        }else{
            subject.setGxsj(new Date());
            subjectDao.update(subject);
        }
    }

    @Override
    @Transactional
    public void delete(Long id) {
        Subject subject=subjectDao.selectById(id);
        subject.setDelMark("1");
        subject.setGxsj(new Date());
        subjectDao.update(subject);
    }

    @Override
    public Subject get(Long id) {
        return subjectDao.selectById(id);
    }

    @Override
    public Boolean isNumberUnique(String number, Long id) {
        return subjectDao.isNumberUnique(number,id);
    }


    @Override
    public List<Subject> findAllByParams(Map<String, Object> map) throws Exception {
        return subjectDao.findAllByParams(map);
    }

    @Override
    public Subject findByParams(Map<String, Object> map) throws Exception {
        return subjectDao.findByParams(map);
    }

    @Override
    @Transactional
    public void deleteAll(Long[] ids) {
        for(Long id:ids){
            delete(id);
        }
    }

}
